{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 《零基础财务Python训练营》实操练习题\n",
    "## Day4《数据处理和分析（上）》"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**作业说明:**  为了帮助同学们掌握、巩固课程学习内容，并主动结合知识点思考问题逻辑，从而形成编程思维，我们为大家设计了2个不同难度的作业~\n",
    "\n",
    "▶基础题：针对当前章节传授知识点设计的题目，用于考察大家的学习掌握情况，同学们一定要尝试做出来哟~\n",
    "\n",
    "▶思考题：针对当前或近期所学内容设计的题目，用于将多个知识点串联、或是引发对后续学习内容的提前思考。同学们可能无法正确解答，但这些内容都是老师精心设计哒，目的是引发大家对知识点的深入探究~我们会有提示引导同学们思考的方向，相信这些思考会让大家不断提高自主探索的能力。\n",
    "\n",
    "★对于以上说明和作业问题，同学们可以在群里积极参与讨论或向助教老师咨询呦，相信大家只要认真完成作业，一定能够收获满满！"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.【基础题】 商品销售情况分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.1 数据库创建\n",
    "<br>商店店主为了提前迎接双十一盛典，想先统计一周以来店铺各类别产品的销量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（1）创捷Series，\n",
    "<br>设置索引为：食品，数码，服装，家电，厨具，饰品，箱包，洗护，运动，保健，\n",
    "<br>对应的销量分别为340,345,678,234,567,789,457,235,467,290"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "食品    340\n",
       "数码    345\n",
       "服装    678\n",
       "家电    234\n",
       "厨具    567\n",
       "饰品    789\n",
       "箱包    457\n",
       "洗护    235\n",
       "运动    467\n",
       "保健    290\n",
       "dtype: int64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "pd.Series([340,345,678,234,567,789,457,235,467,290], \n",
    "          index=['食品', '数码', '服装', '家电', '厨具', '饰品', '箱包', '洗护', '运动', '保健'])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（2）创建DataFrame\n",
    "<br>设置编号code为：1021,1098,1054,1237,1369,1190,1156,1320,1221,1047\n",
    "<br>商品类别types分别为食品，数码，服装，家电，厨具，饰品，箱包，洗护，运动，保健，\n",
    "<br>对应的销量sales分别为340,345,678,234,567,789,457,235,467,290"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>types</th>\n",
       "      <th>sales</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1021</td>\n",
       "      <td>食品</td>\n",
       "      <td>340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1098</td>\n",
       "      <td>数码</td>\n",
       "      <td>345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1054</td>\n",
       "      <td>服装</td>\n",
       "      <td>678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1237</td>\n",
       "      <td>家电</td>\n",
       "      <td>234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1369</td>\n",
       "      <td>厨具</td>\n",
       "      <td>567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1190</td>\n",
       "      <td>饰品</td>\n",
       "      <td>789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1156</td>\n",
       "      <td>箱包</td>\n",
       "      <td>457</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1320</td>\n",
       "      <td>洗护</td>\n",
       "      <td>235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1221</td>\n",
       "      <td>运动</td>\n",
       "      <td>467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1047</td>\n",
       "      <td>保健</td>\n",
       "      <td>290</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   code types  sales\n",
       "0  1021    食品    340\n",
       "1  1098    数码    345\n",
       "2  1054    服装    678\n",
       "3  1237    家电    234\n",
       "4  1369    厨具    567\n",
       "5  1190    饰品    789\n",
       "6  1156    箱包    457\n",
       "7  1320    洗护    235\n",
       "8  1221    运动    467\n",
       "9  1047    保健    290"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "df1 = pd.DataFrame({\n",
    "    'code': [1021,1098,1054,1237,1369,1190,1156,1320,1221,1047],\n",
    "    'types': ['食品', '数码', '服装', '家电', '厨具', '饰品', '箱包', '洗护', '运动', '保健'],\n",
    "    'sales': [340,345,678,234,567,789,457,235,467,290]\n",
    "})\n",
    "\n",
    "df1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>types</th>\n",
       "      <th>sales</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1021</th>\n",
       "      <td>食品</td>\n",
       "      <td>340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1098</th>\n",
       "      <td>数码</td>\n",
       "      <td>345</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1054</th>\n",
       "      <td>服装</td>\n",
       "      <td>678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1237</th>\n",
       "      <td>家电</td>\n",
       "      <td>234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1369</th>\n",
       "      <td>厨具</td>\n",
       "      <td>567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1190</th>\n",
       "      <td>饰品</td>\n",
       "      <td>789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1156</th>\n",
       "      <td>箱包</td>\n",
       "      <td>457</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1320</th>\n",
       "      <td>洗护</td>\n",
       "      <td>235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1221</th>\n",
       "      <td>运动</td>\n",
       "      <td>467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1047</th>\n",
       "      <td>保健</td>\n",
       "      <td>290</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     types  sales\n",
       "code             \n",
       "1021    食品    340\n",
       "1098    数码    345\n",
       "1054    服装    678\n",
       "1237    家电    234\n",
       "1369    厨具    567\n",
       "1190    饰品    789\n",
       "1156    箱包    457\n",
       "1320    洗护    235\n",
       "1221    运动    467\n",
       "1047    保健    290"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#拓展小知识#\n",
    "#我们发现通过index=?的方法可以直接设置索引内容，但创建完DataFrame后，有了默认的索引，我们应该如何进行重置呢？\n",
    "\n",
    "# 直接运行下面代码\n",
    "df1.set_index('code', inplace=True)\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font color=#A64646 size=2> **同学们可以自己尝试一下呦，明天我们依然会用到这个代码的！**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（3）使用loc函数查看编号为1156的商品类别和销量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "types     箱包\n",
       "sales    457\n",
       "Name: 1156, dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "df1.loc[1156, ['types', 'sales']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.2 完善操作\n",
    "<br>店主对统计后的数据进行了核查，核查后店主发现商品的平均价格忘记填写了，另外由于仓库位置有限，店主想要下架编号为1237的家电，下面我们需要进一步完善数据表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（1）使用insert函数添加各商品的平均价格prices:60,980,124,580,98,23,87,31,167,210"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>types</th>\n",
       "      <th>sales</th>\n",
       "      <th>prices</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1021</th>\n",
       "      <td>食品</td>\n",
       "      <td>340</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1098</th>\n",
       "      <td>数码</td>\n",
       "      <td>345</td>\n",
       "      <td>980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1054</th>\n",
       "      <td>服装</td>\n",
       "      <td>678</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1237</th>\n",
       "      <td>家电</td>\n",
       "      <td>234</td>\n",
       "      <td>580</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1369</th>\n",
       "      <td>厨具</td>\n",
       "      <td>567</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1190</th>\n",
       "      <td>饰品</td>\n",
       "      <td>789</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1156</th>\n",
       "      <td>箱包</td>\n",
       "      <td>457</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1320</th>\n",
       "      <td>洗护</td>\n",
       "      <td>235</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1221</th>\n",
       "      <td>运动</td>\n",
       "      <td>467</td>\n",
       "      <td>167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1047</th>\n",
       "      <td>保健</td>\n",
       "      <td>290</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     types  sales  prices\n",
       "code                     \n",
       "1021    食品    340      60\n",
       "1098    数码    345     980\n",
       "1054    服装    678     124\n",
       "1237    家电    234     580\n",
       "1369    厨具    567      98\n",
       "1190    饰品    789      23\n",
       "1156    箱包    457      87\n",
       "1320    洗护    235      31\n",
       "1221    运动    467     167\n",
       "1047    保健    290     210"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "df1.insert(loc=len(df1.columns), column='prices', value=[60,980,124,580,98,23,87,31,167,210])\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（2）使用drop函数删除code为1237的行数据\n",
    "\n",
    "<br>提示：同学们注意呦：这里我们将code设为了索引，直接drop就可以啦，不需要再加引号了哦"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>types</th>\n",
       "      <th>sales</th>\n",
       "      <th>prices</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1021</th>\n",
       "      <td>食品</td>\n",
       "      <td>340</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1098</th>\n",
       "      <td>数码</td>\n",
       "      <td>345</td>\n",
       "      <td>980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1054</th>\n",
       "      <td>服装</td>\n",
       "      <td>678</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1369</th>\n",
       "      <td>厨具</td>\n",
       "      <td>567</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1190</th>\n",
       "      <td>饰品</td>\n",
       "      <td>789</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1156</th>\n",
       "      <td>箱包</td>\n",
       "      <td>457</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1320</th>\n",
       "      <td>洗护</td>\n",
       "      <td>235</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1221</th>\n",
       "      <td>运动</td>\n",
       "      <td>467</td>\n",
       "      <td>167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1047</th>\n",
       "      <td>保健</td>\n",
       "      <td>290</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     types  sales  prices\n",
       "code                     \n",
       "1021    食品    340      60\n",
       "1098    数码    345     980\n",
       "1054    服装    678     124\n",
       "1369    厨具    567      98\n",
       "1190    饰品    789      23\n",
       "1156    箱包    457      87\n",
       "1320    洗护    235      31\n",
       "1221    运动    467     167\n",
       "1047    保健    290     210"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "df1.drop([1237], inplace=True)\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.【基础题】 商店宣传渠道预览"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "数据预览\n",
    "<br>为了吸引客户，商店店主投放了四个渠道进行宣传，下面先看一下各渠道的数据情况"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（1）在python中读取作业中的excel文件，DataFrame的变量名要求为\"data\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#参考答案#\n",
    "\n",
    "data = pd.read_excel('./promotion.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（2）使用head预览数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>时间</th>\n",
       "      <th>渠道A推荐用户数</th>\n",
       "      <th>渠道B推荐用户数</th>\n",
       "      <th>渠道C推荐用户数</th>\n",
       "      <th>渠道D推荐用户数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-01-01</td>\n",
       "      <td>938</td>\n",
       "      <td>542</td>\n",
       "      <td>570</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-01-02</td>\n",
       "      <td>1423</td>\n",
       "      <td>1067</td>\n",
       "      <td>521</td>\n",
       "      <td>392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-01-03</td>\n",
       "      <td>1333</td>\n",
       "      <td>166</td>\n",
       "      <td>557</td>\n",
       "      <td>344</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-01-04</td>\n",
       "      <td>1261</td>\n",
       "      <td>258</td>\n",
       "      <td>537</td>\n",
       "      <td>231</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-01-05</td>\n",
       "      <td>1198</td>\n",
       "      <td>805</td>\n",
       "      <td>503</td>\n",
       "      <td>556</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          时间  渠道A推荐用户数  渠道B推荐用户数  渠道C推荐用户数  渠道D推荐用户数\n",
       "0 2020-01-01       938       542       570       133\n",
       "1 2020-01-02      1423      1067       521       392\n",
       "2 2020-01-03      1333       166       557       344\n",
       "3 2020-01-04      1261       258       537       231\n",
       "4 2020-01-05      1198       805       503       556"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（3）使用shape获取数据表大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(366, 5)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（4）使用info获取数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 366 entries, 0 to 365\n",
      "Data columns (total 5 columns):\n",
      " #   Column    Non-Null Count  Dtype         \n",
      "---  ------    --------------  -----         \n",
      " 0   时间        366 non-null    datetime64[ns]\n",
      " 1   渠道A推荐用户数  366 non-null    int64         \n",
      " 2   渠道B推荐用户数  366 non-null    int64         \n",
      " 3   渠道C推荐用户数  366 non-null    int64         \n",
      " 4   渠道D推荐用户数  366 non-null    int64         \n",
      "dtypes: datetime64[ns](1), int64(4)\n",
      "memory usage: 14.4 KB\n"
     ]
    }
   ],
   "source": [
    "#参考答案# \n",
    "\n",
    "data.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（5）使用describle获取数值分布情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>渠道A推荐用户数</th>\n",
       "      <th>渠道B推荐用户数</th>\n",
       "      <th>渠道C推荐用户数</th>\n",
       "      <th>渠道D推荐用户数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>366.000000</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>366.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1003.994536</td>\n",
       "      <td>584.019126</td>\n",
       "      <td>547.877049</td>\n",
       "      <td>344.909836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>289.864068</td>\n",
       "      <td>281.216247</td>\n",
       "      <td>29.870839</td>\n",
       "      <td>146.461927</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>504.000000</td>\n",
       "      <td>106.000000</td>\n",
       "      <td>500.000000</td>\n",
       "      <td>101.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>747.000000</td>\n",
       "      <td>340.250000</td>\n",
       "      <td>521.250000</td>\n",
       "      <td>218.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1020.500000</td>\n",
       "      <td>601.000000</td>\n",
       "      <td>546.000000</td>\n",
       "      <td>338.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1253.500000</td>\n",
       "      <td>804.500000</td>\n",
       "      <td>575.750000</td>\n",
       "      <td>469.750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1498.000000</td>\n",
       "      <td>1099.000000</td>\n",
       "      <td>599.000000</td>\n",
       "      <td>599.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          渠道A推荐用户数     渠道B推荐用户数    渠道C推荐用户数    渠道D推荐用户数\n",
       "count   366.000000   366.000000  366.000000  366.000000\n",
       "mean   1003.994536   584.019126  547.877049  344.909836\n",
       "std     289.864068   281.216247   29.870839  146.461927\n",
       "min     504.000000   106.000000  500.000000  101.000000\n",
       "25%     747.000000   340.250000  521.250000  218.250000\n",
       "50%    1020.500000   601.000000  546.000000  338.000000\n",
       "75%    1253.500000   804.500000  575.750000  469.750000\n",
       "max    1498.000000  1099.000000  599.000000  599.000000"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "data.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.【思考题】 商店宣传渠道分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（1）求出四个渠道分别推荐用户数总和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "渠道A推荐用户数    367462\n",
       "渠道B推荐用户数    213751\n",
       "渠道C推荐用户数    200523\n",
       "渠道D推荐用户数    126237\n",
       "dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "data.sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "（2）求出四个渠道分别推荐用户数的平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "#请在此输入答案并运行#\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-26-d6a7f172ca2d>:3: FutureWarning: DataFrame.mean and DataFrame.median with numeric_only=None will include datetime64 and datetime64tz columns in a future version.\n",
      "  data.mean()\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "渠道A推荐用户数    1003.994536\n",
       "渠道B推荐用户数     584.019126\n",
       "渠道C推荐用户数     547.877049\n",
       "渠道D推荐用户数     344.909836\n",
       "dtype: float64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#参考答案#\n",
    "\n",
    "data.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font color=#A64646 size=2> **同学们真棒，看来大家已经掌握本节课的数据分析方法啦！**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font color=#A64646 size=2> **继续加油喔，快和小伙伴一起开启明天的课程学习吧！**"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
